// MAC地址授权服务

// 模拟授权的MAC地址列表
const authorizedMacAddresses = [
  // 这里可以添加预设的授权MAC地址
  // 例如：'00:1A:2B:3C:4D:5E'
];

// 检查MAC地址是否已授权
export const checkMacAuthorization = (macAddress) => {
  if (!macAddress) return false;
  
  // 检查MAC地址是否在授权列表中
  return authorizedMacAddresses.some(addr => addr.toLowerCase() === macAddress.toLowerCase());
};

// 添加MAC地址到授权列表
export const addAuthorizedMac = (macAddress) => {
  if (!macAddress) return false;
  
  // 标准化MAC地址格式
  const normalizedMac = macAddress.toLowerCase();
  
  // 检查是否已存在
  if (authorizedMacAddresses.includes(normalizedMac)) {
    return true; // 已授权
  }
  
  // 添加到授权列表
  authorizedMacAddresses.push(normalizedMac);
  return true;
};

// 从授权列表移除MAC地址
export const removeAuthorizedMac = (macAddress) => {
  if (!macAddress) return false;
  
  const normalizedMac = macAddress.toLowerCase();
  const index = authorizedMacAddresses.indexOf(normalizedMac);
  
  if (index !== -1) {
    authorizedMacAddresses.splice(index, 1);
    return true;
  }
  
  return false;
};

// 获取授权状态
export const getAuthorizationStatus = () => {
  // 从localStorage获取当前MAC地址和授权状态
  const currentMac = localStorage.getItem('macAddress');
  const isAuthorized = localStorage.getItem('isAuthorized') === 'true';
  
  return {
    macAddress: currentMac,
    isAuthorized: isAuthorized
  };
};

// 设置授权状态
export const setAuthorizationStatus = (macAddress, isAuthorized) => {
  localStorage.setItem('macAddress', macAddress);
  localStorage.setItem('isAuthorized', isAuthorized.toString());
  
  return {
    macAddress,
    isAuthorized
  };
};